/**
 * @param {number} target
 * @param {number} maxDoubles
 * @return {number}
 */
 var minMoves = function(target, maxDoubles) {
  let ans = 0
  while(maxDoubles-- && target >= 2){
    if(target % 2 === 0){
      target /= 2
      ans++
    }else{
      target -= 1
      target /= 2
      ans += 2
    }
  }
  return ans + target - 1
};